home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Fun House 8
/
CD Funhouse Version 8.0 - Wayzata Technology (7013) (1993).iso
/
pc
/
pc
/
cards
/
bidding
/
deal.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-14
|
2KB
|
97 lines
/* deal.c */
/*
Bridge Bidder Version 2.0
by Nathan Glasser
nathan@brokaw.lcs.mit.edu (internet)
nathan@mit-eddie.uucp (usenet)
February, 1989
------------------------------------------------------------------------------
Copyright 1988, 1989 by Nathan Glasser.
You may feel free to distribute this program in its current form.
Please do not remove this copyright information.
*/
#include "bidding.h"
card_compare(pcard1,pcard2)
card *pcard1,*pcard2;
{
return((pcard1->suit != pcard2->suit) ? (pcard1->suit - pcard2->suit) :
(pcard2->rank - pcard1->rank));
}
deal_hands(pdeal)
deal *pdeal;
{
card *thehand;
int cards[52];
int player,cardsinhand;
int cardnum;
int nextcard;
int cardsleft = 52;
static vulnerability = 0;
pdeal->num_bids = 0;
pdeal->bidding_done = 0;
vulnerability = ((pdeal->vulnerability = vulnerability) + 1) % 4;
pdeal->opening_lead.rank = pdeal->opening_lead.suit = -1;
for (cardnum = 0; cardnum < 52; cardnum++)
cards[cardnum] = 0;
for (player = 0; player < 4; player++)
{
thehand = pdeal->hands[player];
for (cardsinhand = 0; cardsinhand < 13; cardsinhand++)
{
nextcard = random() % (cardsleft--);
for (cardnum = 0 ; cards[cardnum] || --nextcard >= 0; cardnum++);
cards[cardnum] = 1;
thehand[cardsinhand].suit = cardnum / 13;
thehand[cardsinhand].rank = 2 + (cardnum % 13);
}
qsort(thehand,13,sizeof(card),card_compare);
}
}
print_hand(fp,thehand)
FILE *fp;
card *thehand;
{
int i;
char bufs[4][80];
format_hand(bufs,thehand);
for (i = 0; i < 4; i++)
{
fputs(bufs[i],fp);
putc('\n',fp);
}
}
/* Accepts an array of size four of strings, and formats into it */
format_hand(bufs,thehand)
char (*bufs)[80];
card *thehand;
{
extern char *suit_strings[];
static char card_chars[] = "xx23456789TJQKA";
int suit_num = -1;
int i;
static char card_str[3] = " A";
bufs--;
for (i = 0; i < 13; i++)
{
while (thehand[i].suit != suit_num)
sprintf(*++bufs,"%8s: ",suit_strings[++suit_num]);
card_str[1] = card_chars[thehand[i].rank];
strcat(*bufs,card_str);
}
while (suit_num < 3)
sprintf(*++bufs,"%8s: ",suit_strings[++suit_num]);
}